﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StorageTime.aspx.cs" Inherits="Web.BasicData.StoragePara.StorageTime" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="../../Styles/Common.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Common.js" type="text/javascript"></script>
    <script src="../../Scripts/WebInner.js" type="text/javascript"></script>
    <script src="../../Scripts/Zebra/zebra_dialog.js" type="text/javascript"></script>
    <link href="../../Scripts/Zebra/zebra_dialog.css" rel="stylesheet" type="text/css" />
    <style type="text/css">

</style>
    <script type="text/javascript">
     
        $(function () {

            //显示网点类型,操作级别
            $.ajax({
                url: '/BasicData/StoragePara/storage.ashx?type=GetStorageType',
                type: 'post',
                data: '',
                dataType: 'json',
                success: function (r) {
                    for (var i = 0; i < r.length; i++) {
                        $('select[name=TypeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                    }
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>加载存储产品名称失败 ！</strong>');
                }
            });
        });


        function ShowFrm(wbid) {
            $('#divfrm').fadeIn("normal");
            $('#WBID').val(wbid);
            if (wbid == "0") {
                $('#trAdd').fadeIn("fast");
                $('#trUpdate').fadeOut("fast");
                $('select[name=TypeID]').removeAttr('disabled');
                $('select[name=TypeID]').get(0).selectIndex = 0;
                $('input[name=strName]').val('');
                $('input[name=ISRegular]').removeAttr('checked');
                $('input[name=CalculateInterest]').removeAttr('checked');
                $('input[name=numStorageDate]').val('0');
                $('input[name=numExChangeProp]').val('0.000');
                $('input[name=PricePolicy]').val('90');
                $('input[name=InterestType]:eq(0)').attr('checked','checked');
            }
            else { //编辑网点
                $('#trAdd').fadeOut("fast");
                $('#trUpdate').fadeIn("fast");

                /*--------数据提交--------*/
                $.ajax({
                    url: 'storage.ashx?type=GetStorageTimeByID&ID=' + wbid,
                    type: 'post',
                    data: '',
                    dataType: 'json',
                    success: function (r) {
                        $('input[name=txtTypeID]').val(r[0].TypeID);
                        $("select[name=TypeID]  option[value='" + r[0].TypeID + "'] ").attr("selected", 'selected');
                        $('select[name=TypeID]').attr('disabled', 'disabled');
                        $('input[name=strName]').val(r[0].strName);
                        $('input[name=ISRegular]').removeAttr('checked');
                        $('input[name=numStorageDate]').val(r[0].numStorageDate);
                        $('input[name=numExChangeProp]').val(r[0].numExChangeProp);
                        $('input[name=PricePolicy]').val(r[0].PricePolicy);
                      
                        var InterestType = parseInt(parseInt(r[0].InterestType) - 1);
                        $('input[name=InterestType]:eq(' + InterestType + ')').attr('checked', 'checked');
                        // $('input[name=InterestType]:eq(0)').attr('checked', 'checked');

                        if (r[0].CalculateInterest == true) {
                            $('input[name=CalculateInterest]').attr('checked', 'checked');
                        } else {
                            $('input[name=CalculateInterest]').removeAttr('checked');
                        }
                        if (r[0].ISRegular == true) {
                            $('input[name=ISRegular]').attr('checked', 'checked');
                        } else {
                            $('input[name=ISRegular]').removeAttr('checked');
                        }

                    }, error: function (r) {
                        $.Zebra_Dialog('<strong>加载信息失败 ！</strong>');
                    }
                });
                /*--------End 数据提交--------*/
            }
        };
        function CloseFrm() {
            $('#divfrm').fadeOut("normal");
        }

        //添加、修改网点 （ID=0是添加网点）
        function WBUpdate() {
            if (!SubmitCheck()) {//检测输入内容
                return false;
            }
            var wbid = $('#WBID').val();
            if (confirm("您确认已经仔细检查输入信息，并继续操作吗？")) {
                var strurl = 'storage.ashx?type=UpdateStorageTime&ID=' + wbid;
                if (wbid == "0") {
                    strurl = 'storage.ashx?type=AddStorageTime&ID=' + wbid;
                }
                /*--------数据提交--------*/
                $.ajax({
                    url: strurl,
                    type: 'post',
                    data: $('#form1').serialize(),
                    dataType: 'txt',
                    success: function (r) {
                        if (r == "OK") {
                            if (wbid == "0") {
                                $.Zebra_Dialog('<strong>添加数据成功 ！</strong>');
                            } else {
                                $.Zebra_Dialog('<strong>更新数据成功 ！</strong>');
                            }
                            CloseFrm();
                            location.reload();
                        } else if (r == "1") {
                            $.Zebra_Dialog('<strong>已存在相同的储户类型名称，请修改后添加 ！</strong>');
                        }
                    }, error: function (r) {
                        $.Zebra_Dialog('<strong>操作失败 ！</strong>');
                    }
                });

            }
        }



        //提交检测
        function SubmitCheck() {
            if (!CheckSelect('TypeID', '存储类型')) {
                return false;
            }
            if (!CheckInput('strName', '存期名称', '-1')) {
                return false;
            }
            if (!CheckNumInt($('input[name=numStorageDate]').val(), '约定实存天数', '-1')) {
                return false;
            }
            if (!CheckNumDecimal($('input[name=numExChangeProp]').val(), '约定兑换比例',3)) {
                return false;
            }
            if (!CheckNumInt($('input[name=PricePolicy]').val(), '价格政策期限', -1,-1)) {
                return false;
            }
            return true;
        }


        function FunDelete(wbid) {

            if (confirm("您确认要删除此存储期限吗？")) {
                /*--------数据提交--------*/
                $.ajax({
                    url: 'storage.ashx?type=DeleteStorageTimeByID&ID=' + wbid,
                    type: 'post',
                    data: '',
                    dataType: 'txt',
                    success: function (r) {

                        if (r == "Exit") {
                            $.Zebra_Dialog('<strong>该信息已经在系统中使用，无法删除！</strong>', {
                                'type': 'warning',
                                'title': 'warning'
                            });
                        }
                        else if (r == "OK") {
                            $.Zebra_Dialog('<strong>删除数据成功！</strong>');
                            CloseFrm();
                            location.reload();
                        } else {
                            $.Zebra_Dialog('<strong>删除数据失败 ！</strong>');
                        }
                    }, error: function (r) {
                        $.Zebra_Dialog('<strong>删除数据失败 ！</strong>');
                    }
                });
                /*--------End 数据提交--------*/

            }
        }

        $(function () {
            InitPolicy();//获取价格政策
            $('#aPolicy').toggle(function () {
                $('#divPricePolicy').slideDown('normal');
            }, function () {
                $('#divPricePolicy').slideUp('normal');
            });

        });
        function InitPolicy() {

            $.ajax({
                url: 'storage.ashx?type=getPricePolicy',
                type: 'post',
                data: '',
                dataType: 'json',
                success: function (r) {
                    $('#strPolicy').val(r[0].strRemark);
                    $('#strLink').val(r[0].strLink);
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>加载价格政策失败 ！</strong>');
                }
            });

        }



        //保存价格政策
        function SavePolicy() {
            console.info('2222');
//            if (!CheckNumInt($('#strLink').val()), "时间期限", -1, -1) {
//                return false;
            //            }
            if (isNaN($('#strLink').val())) {
                $.Zebra_Dialog('<strong>时间期限文本框中请输入一个整数 ！</strong>');
                return;
            }
          
            console.info('jjlk');
            $.ajax({
                url: 'storage.ashx?type=SavePricePolicy&strPolicy=' + $('#strPolicy').val() + '&strLink=' + $('#strLink').val(),
                type: 'post',
                data: '',
                dataType: 'txt',
                success: function (r) {
                    if (r == "OK") {
                        $.Zebra_Dialog('<strong>更新价格政策成功！</strong>');
                      
                    } else {
                        $.Zebra_Dialog('<strong>更新价格政策失败 ！</strong>');
                    }
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>更新价格政策失败 ！</strong>');
                }
            });
        }




    </script>
</head>
<body>
     <form id="form1" runat="server">
<div class="pageHead">
<b>存储期限设置</b><span id="spanHelp" style="cursor:pointer" >帮助</span>
</div>
<div id="divHelp"  class="pageHelp">
<span>提示1：请认真设置产品的存期和付息类型。</span><br />
<span>提示2：请根据你们的实际情况设置粮食银行系统中的存储期限名称、实际存储天数、定期储粮储户享受到期价兑换商品的优惠比例（正数）。实际存储天数应为30的正整数倍，现粮的存期为0天。</span><br />
<span>提示3：兑换优惠比例是指定期储粮（不论到期与否）在指定的额度内用到期价兑换（实际上是给储户很大的优惠），优惠额度用比例体现，超过部分用存入价兑换。</span><br />
<span>提示4：设置完成后，最好不要删除，否则会造成已经存在的数据找不到对应的存期。</span><br />
</div>

<div class="QueryHead">
<table>
            <tr>
            <td><b>已有存储期限列表</b></td>
            
            <td><%=GetAddItem() %></td>
            <td style="width:100px;"></td>
              <td><a href="#" id="aPolicy">设置价格政策</td>
            </tr>
            
        </table>
        <div id="divPricePolicy"  class="pageHelp" style="display:none;">
        <table>
            <tr>
            <td align="right" style="width:150px; height:30px;"><span>价格政策:</span></td>
            
            <td><input type="text" id="strPolicy"  style="width:500px;" /></td>
              <td></td>
               <td rowspan="2"><input type="button" id="btnPoicy" value="保存价格政策" onclick="SavePolicy();" style="width:100px; font-weight:bolder;" /> </td>
            </tr>
            <tr>
            <td></td>
            <td>存储不满<input type="text" id="strLink" style="width:50px;" />天，存转销不计利息</td>
            </tr>
            
        </table>
</div>
</div>
<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <table  class="tabData" style="width:900px">
          <tr class="tr_head" >
                <th style="width:200px; text-align:center;">
                    存储类型</th>
                    <th style="width:100px; text-align:center;">
                    存储期限</th>
                    <th style="width:100px; text-align:center;">
                    约定存储天数</th>
                    <th style="width:100px; text-align:center;">
                    兑换商品计息</th>
                    <th style="width:100px; text-align:center;">
                    兑换优惠比例</th>
                
                    <th style="width:120px; text-align:center;">
                    查看/修改</th>
                   <th style="width:100px; text-align:center;">
                    删除</th>
                
            </tr>
        
    </HeaderTemplate>
    <ItemTemplate>
    <tr style='background-color: <%#(Container.ItemIndex%2==0)?"#FFFFF;":"#fcf3f4"%>' onmouseover="change_colorOver(this)" onmouseout="change_colorOut(this)">
        <td><%#Eval("TypeID")%></td>
         <td><%#Eval("strName")%></td>
          <td><%#Eval("numStorageDate")%></td>
          <td><%#Eval("CalculateInterest")%></td>
          <td><%#Eval("numExChangeProp")%>%</td>
         <td> <%# GetUpdateItem(Eval("ID")) %> </td>
      <td> <%# GetDeleteItem(Eval("ID")) %></td>
   
    </tr>
    </ItemTemplate>
    
    <FooterTemplate><!--底部模板-->
        </table>        <!--表格结束部分-->
        </FooterTemplate>
    </asp:Repeater>
   <div class="divWarning">
   <b>特别提示:</b><span>这是系统关键数据，最好不要添加、修改、删除!</span>
   </div>
    <div  id="divfrm" class="pageEidt" style="display:none; left:100px; width:460px; height:380px;">
    <div style="float:right; margin:10px 20px"> <img src="../../images/winClose.png" alt="关闭窗口"  style="float:right; cursor:pointer;" onclick="CloseFrm()" /></div>    
   
    <div style="clear:both;">
        <table class="tabEdit">
            
            <tr>
            <td align="right" style="width:120px;"><span>储户类型:</span></td>
            <td><select name="TypeID" style="width:150px;" ></select></td>
            </tr>
            <tr>
            <td align="right"><span>存储期限名称:</span></td>
            <td><input type="text" name="strName" style="width:150px; " /></td>
            </tr>
             <tr>
            <td align="right" ><span>设为定期类型:</span></td>
            <td><input type="checkbox"  name="ISRegular" /><span style="font-size:12px;">(定期产品在未到约定期限内不计算利息)</span></td>
            </tr>
            <tr>
           <td align="right" ><span>约定存储天数:</span></td>
            <td><input type="text" name="numStorageDate" style="width:40px;" /><span style="font-size:12px;">(定期产品请输入存储天数，非定期产品不做要求)</span></td>
            </tr>
             <tr>
           <td align="right" ><span>利息计算方式:</span></td>
            <td>
            <input type="radio" value="1" name="InterestType" /> <span>每月按照活期利率计息</span><br />
             <input type="radio" value="2" name="InterestType" /> <span>按照到时市场价计息</span><br />
              <input type="radio" value="3" name="InterestType" /> <span>按照约定到期价格计息</span><br />
               <input type="radio" value="4" name="InterestType" /> <span>按照约定合同价计息</span>
            </td>
            </tr>
            <tr>
            <td align="right" ><span>兑换商品计息:</span></td>
            <td><input type="checkbox" name="CalculateInterest"/>兑换商品时计利息</td>
            </tr>
             <tr>
            <td align="right" ><span>价格政策:</span></td>
            <td>存储不满<input type="text" name="PricePolicy" style="width:40px; " />天，按约定收取保管费</td>
            </tr>
            <tr>
            <td align="right" ><span>兑换优惠比例:</span></td>
            <td><input type="text" name="numExChangeProp" style="width:40px; " />%</td>
            </tr>
             
            <tr id="trAdd">
            <td></td>
            <td ><input type="button" id="btnAdd" value="添加" onclick="WBUpdate()" /> </td>
            </tr>
               <tr id="trUpdate">
            <td></td>
            <td ><input type="button" id="btnUpdate" value="修改" onclick="WBUpdate()" />
         
             </td>
            </tr>
        </table>
        </div>
    </div>
    <div style="display:none">
     <input type="text" name="txtTypeID" value="" />
    </div>
    </form>
    <%--定义编号--%>
    <input type="hidden" id="WBID" value="" />
    <%--定义背景色的隐藏域--%>
    <input type="hidden" id="colorName" value="" />
</body>
</html>


